package com.chinaunicom.emergency.repository;

import com.chinaunicom.emergency.model.UserRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author liliang
 * @date 2019-12-13
 * 角色
 */
public interface UserRoleRepository extends JpaRepository<UserRole,String>, JpaSpecificationExecutor {

    List<UserRole> findByUserIdAndIsSoftDel(String userId, Integer isSoftDel);

    @Query(nativeQuery = true,value = "select ROLE_ID from YJGL_USERROLE where USER_ID = ?1 and IS_SOFT_DEL = 0 ")
    List<String> findRoleIdByUserId(String userId);


    @Query(nativeQuery = true,value = "select u.USER_NAME from YJGL_USERROLE ur, YJGL_USER u where ur.ROLE_ID = ?1 and ur.IS_SOFT_DEL = 0 and ur.USER_ID = u.PID")
    List<String> findUserNameByRoleId(String roleId);

    void deleteByUserId(String userId);

}
